package jsonjx;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class  ChoiceAnimalJX {
	
	
	private List<String> listofmain = new ArrayList<String>();
	
	private static ChoiceAnimalJX instance = null;

	public  ChoiceAnimalJX (){
		
	}
	public static ChoiceAnimalJX getInstance(){
		if(instance == null){
			instance = new ChoiceAnimalJX();
		}
		return instance;
	}

	
	public String [] getshuzuofmain(){
		
		 int lengthoflistofmain = listofmain.size() ;
		 String [] returnshuzu = new String [lengthoflistofmain] ;
		 int jishuofchoice = -1;
		 for(String name : listofmain)
		 {
			 jishuofchoice++;
			 returnshuzu[jishuofchoice] = name;
			 
		 }
		
		return returnshuzu;
		
		
	}
	
	public void jxmain (String result){

		try {
			
			JSONArray jsonjxofmain = new JSONObject(result).getJSONArray("animal");
			
			
			JSONObject jsonObj = ((JSONObject)jsonjxofmain.opt(0)) ;
			
			System.out.println("   ________________" + jsonObj);
			
			String nameofanimalofmain = jsonObj.getString("animalName");
			
			System.out.println("##############" + nameofanimalofmain);
			
			listofmain.add(nameofanimalofmain);
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
	}


}
